package cz.vutbr.fit.xzemko01.tfmcbs.validation.validators;

import java.util.Map;

import org.eclipse.emf.common.util.DiagnosticChain;

import cz.vutbr.fit.xzemko01.tfmcbs.model.Port;
import cz.vutbr.fit.xzemko01.tfmcbs.model.Requier;
import cz.vutbr.fit.xzemko01.tfmcbs.model.RequiringPort;

public class RequiringPortValidator implements Validator<RequiringPort> {
	
	private static RequiringPortValidator requiringPortValidator;
	
	private Validator<Requier> requierValidator;
	private Validator<Port> portValidator; 
	
	private RequiringPortValidator() {
		requierValidator = RequierValidator.getInstance();
		portValidator = PortValidator.getInstance();
	}
	
	public static Validator<RequiringPort> getInstance() {
		if(requiringPortValidator == null) {
			requiringPortValidator = new RequiringPortValidator();
		}
		return requiringPortValidator;
	}
	
	@Override
	public boolean validate(RequiringPort port, DiagnosticChain diagnostics, Map<Object, Object> context) {
		boolean result = portValidator.validate(port, diagnostics, context);
		result &= requierValidator.validate((RequiringPort) port, diagnostics, context);

		return result;
	}
}
